//类的构造，传入xml文档和需要处理的标签名称
function datasource(xml,tagLabel){
   //alert(1);
   this.rootObj = xml.getElementsByTagName(tagLabel);
    //alert(2);
   this.getCount = getCount;
   //alert(3);
   this.getAttribute = getAttribute;
}
function getCount() {
   // alert(21);
	return this.rootObj.length;
}
function getAttribute(index, tagName) {
    //alert(31);
	var node = this.rootObj[index];
	//alert(32);
	var str = node.getAttribute(tagName);
	//alert(33);
	return str;
}
//如何使用datasource类
function updateByXML(xmlDoc) {
    //alert(xmlDoc);
	var ds = new datasource(xmlDoc, "item");  //关心的标签名称 
	//alert(41)
	var count = ds.getCount();
	//alert(42)
	for (i = 0; i < count; i++) {
	    //alert(43)
		var categoryID = ds.getAttribute(i, "categoryID");
		//alert(44)
		var categoryName = ds.getAttribute(i, "categoryName");
		//alert(45)
		var resultsCount = ds.getAttribute(i, "resultsCount");
		alert(categoryID + "," + categoryName + "," + resultsCount);
	}
}


